function jumpto(){
    var input_name=document.getElementById("name").value;
    var input_password=document.getElementById("password").value;
    if(input_name=="Nolan"&&input_password=="2019211524"){
        window.alert("登录成功");
        window.open('booklist.html');
    }
    else
        window.alert("用户名和密码错误");
}
function isempty(input){
    if (input==null||input=="")
        return 0;
    else return 1;
}

function submit(){
    var input_name=document.getElementById("book_name").value;
    var input_author=document.getElementById("author").value;
    var input_press=document.getElementById("publish_press").value;
    var input_year=document.getElementById("publish_year").value;
    var input_month=document.getElementById("publish_month").value;
    var input_number=document.getElementById("store_number").value;
    submit_state=1;
    var nowdate=new Date();
    var mydate=new Date();

    mydate.setFullYear(input_year,input_month,0);
    if(isempty(input_name)==0) {
        window.alert("图书姓名不能为空");
        submit_state=0;
    }
    else if(isempty(input_author)==0) {
        window.alert("图书作者不能为空");
        submit_state=0;
    }
    else if(isempty(input_press)==0) {
        window.alert("图书出版社不能为空");
        submit_state=0;
    }
    else if(isempty(input_year)==0||isempty(input_month)==0) {
        window.alert("出版时间不能为空");
        submit_state=0;
    }
    else if(mydate>nowdate){
        window.alert("出版时间晚于当前日期");
        submit_state=0;
    }
    else if(isempty(input_number)==0) {
        window.alert("在售数目不能为空");
        submit_state=0;
    }else if(input_number<0||NaN(input_number)){
        window.alert("在售数目输入不合法")
        submit_state=0;
    }
    if (submit_state==1)
        window.alert("提交成功，后台正在处理");
}

function load_img(){
    var file=document.getElementById("image_file");
    var image=document.querySelector("img");
    file.onchange = function (){
        var fileData = this.files[0];
        var pattern=/^image/;
        console.info(fileData.type);
        if(!pattern.test(fileData.type)){
            window.alert("图片格式不正确");
            return 0;
        }
        var reader = new FileReader();
        reader.readAsDataURL(fileData);
        reader.onload = function(e) {
            image.setAttribute("src", this.result)
        }
    }
}